Method Name | Description | Exception Case |
---|---|---|
next | Return next data element and move to next | If at end, throw runtime exception "no more elements" |
hasNext | If NOT at end, return true, else false | None |
iterator = myArrayedList.toIterator() While iterator.hasNext() print(iterator.next());
iterator = myLinkedList.toIterator() While iterator.hasNext() print(iterator.next());
iterator = myComplexTree.toIterator() While iterator.hasNext() print(iterator.next());
While iterator.hasNext() print(iterator.next());
Given this input: list = [10, 20, 30, 40] The expected output is shown
10 20 30 40